<template>
  <div class="News-container">
    <ul>
      <li v-for="item in newList" :key="item.id">
        <button @click="showDetail(item)">查看详情</button>
        <RouterLink
          :to="{
            path: '/news/detail',
            query: {
              id: item.id,
              title: item.title,
              content: item.content,
            },
          }"
        >
          {{ item.title }}
        </RouterLink>
      </li>
    </ul>
    <div class="content">
      <RouterView />
    </div>
  </div>
</template>

<script setup lang="ts" name="News">
import { reactive } from "vue";
import { RouterView, RouterLink, useRouter } from "vue-router";

// type Props = {}
// defineProps<Props>()
// const emit = defineEmits([])
// const router = useRouter()
// const route = useRoute()
let newList = reactive<NewInterface[]>([
  { id: "fdsaffwer01", title: "第一条消息", content: "第一条消息的内容" },
  { id: "fdsaffwer02", title: "第二条消息", content: "第二条消息的内容" },
  { id: "fdsaffwer03", title: "第三条消息", content: "第三条消息的内容" },
  { id: "fdsaffwer04", title: "第四条消息", content: "第四条消息的内容" },
  { id: "fdsaffwer05", title: "第五条消息", content: "第五条消息的内容" },
]);
let router = useRouter();
interface NewInterface {
  id: string;
  title: string;
  content: string;
}
function showDetail(item: NewInterface) {
  router.push({
    path: "/news/detail",
    query: {
      id: item.id,
      title: item.title,
      content: item.content,
    },
  });
}
</script>

<style scoped lang="scss">
.News-container {
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  height: 100%;
  .ul {
    margin-top: 30px;
    list-style: none;
    padding-left: 10px;
  }
  .li > a {
    font-size: 18px;
    line-height: 40px;
    text-decoration: none;
    color: #64967e;
    text-shadow: 0 0 1px rgb(0, 84, 0);
  }
  .content {
    width: 70%;
    height: 90%;
    border: 1px solid;
    margin-top: 20px;
    border-radius: 10px;
  }
}
</style>
